<?php
define('FPDF_FONTPATH', 'font/');
require('./font/fpdf.php');
include("include/config.inc.php");
if(!isset($_SESSION['s_activId']))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
  $pdf=new FPDF('P','mm','A4');   //Create new pdf file
  $pdf->Open();     //Open file
  $pdf->SetAutoPageBreak(false);  //Disable automatic page break
  $pdf->AddPage();  //Add first page

  $i         = 0; 
  $rowHeight = 6;
  $yAxis     = 19;

  $yAxis += $rowHeight;
  
  pageHeader();
  pageHeaderMIddle();
  
  $select = "SELECT outgoingMasterId,DATE_FORMAT(date,'%d-%m-%Y') AS outDate,partyName,outChallenNo,dispatchQuantity,materialName
               FROM outgoingmaster
               JOIN incoming ON outgoingmaster.incomingId = incoming.incomingId
               JOIN party ON incoming.partyId = party.partyId
               JOIN material ON incoming.materialId = material.materialId
              WHERE outChallenNo = ".$_GET['outChallenNo']."
           ORDER BY outgoingMasterId";
  $selectResult = mysql_query($select);
  while($row = mysql_fetch_array($selectResult))
  {
    $outChallenNo     = $row['outChallenNo'];
    $outDate          = $row['outDate'];
    $partyName        = $row['partyName'];
    $dispatchQuantity = $row['dispatchQuantity'];
    $materialName     = $row['materialName'];
  
    $pdf->SetTextColor(0,0,0);
    $pdf->SetFont('Arial', '', 12);
    $pdf->SetXY(5,$yAxis + 43);
    $pdf->Cell(80 ,6, $materialName,0,0,'L');
    
    $pdf->SetXY(85,$yAxis + 43);
    $pdf->Cell(40 ,6, $dispatchQuantity,0,0,'R');
    
    $yAxis += $rowHeight;
    $i++;
  }
  
  $pdf->Line(85,68,85,$yAxis+47);
  $pdf->Line(125,68,125,$yAxis+47);
  $pdf->Line(165,68,165,$yAxis+47);
  $pdf->Line(5,68,5,$yAxis+47);
  $pdf->Line(205,68,205,$yAxis+47);
  
  $pdf->Line(5,$yAxis+47,205,$yAxis+47);

  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,$yAxis+42);
  $pdf->Cell(80, 5, '+ Taxes Extra As Applicable', 1, 0, 'C', 0);
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(34,46);
  $pdf->Cell(180, 5, $outChallenNo,0,0,'L');
  
  $pdf->SetXY(145,46);
  $pdf->Cell(180, 5, $outDate,0,0,'L');
  
  $pdf->SetXY(18,55);
  $pdf->Cell(180, 5, $partyName,0,0,'L');
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,$yAxis+52);
  $pdf->Cell(200, 5, 'Material As Above Checked End Received Good Condition.', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,$yAxis+70);
  $pdf->Cell(100, 5, 'Receivers Signature', 0, 0, 'L', 0);
  
  $pdf->SetXY(105,$yAxis+70);
  $pdf->Cell(100, 5, 'For, Shakti Heat-Treaters & Engineers', 0, 0, 'R', 0);
  
  $yAxis += $rowHeight;
  $i++;
  
  $pdf->Output();
}
function pageHeader()
{
  global $pdf;
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 15);
  $pdf->SetXY(5,5);
  $pdf->Cell(85, 5, 'Shakti Heat-Treaters & Engineers', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,10);
  $pdf->Cell(85, 5, 'Speciallst In All Types Of Heat Treatment Process', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,15);
  $pdf->Cell(85, 5, 'AN ISO 9000:2000 Certified Company', 0, 0, 'C', 0);
  
  $pdf->Image('./logo/logo_21108.gif',154,3,50,18);
  $pdf->Line(5,22,205,22);
}

function pageHeaderMIddle()
{
  global $pdf;
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,23);
  $pdf->Cell(90, 5, 'Sr. No.  163/1 - p,  Plot No. 3,  S.I.D.C. Road', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,27);
  $pdf->Cell(90, 5, 'VERAVAl (SHAPAR), Ta.Kotda Sangani, Dist : Rajkot', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,31);
  $pdf->Cell(90, 5, 'Tel. :(02827)-252067 Mo. :99740 38980 / 99740 12322', 0, 0, 'L', 0);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,35);
  $pdf->Cell(98, 5, 'Email : shaktiheat@gmail.com  -  shaktiheat@yahoo.co.in', 0, 0, 'L', 0);
  

  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 12);
  $pdf->SetXY(5,46);
  $pdf->Cell(121, 5, 'Challan No. :',   0, 0, 'L', 0);
  $pdf->Line(34,51,125,51);
  
  $pdf->SetXY(130,46);
  $pdf->Cell(62, 5, 'Date. :',  0, 0, 'L', 0);
  $pdf->Line(145,51,190,51);
  
  $pdf->SetXY(5,56);
  $pdf->Cell(186, 5, 'Ms. :',  0, 0, 'L', 0);
  $pdf->Line(18,60,191,60);
  
  $pdf->SetTextColor(0,0,0);
  $pdf->SetFont('Arial', 'B', 10);
  $pdf->SetXY(5,62);
  $pdf->Cell(80, 6, 'Party Name',   1, 0, 'C', 0);
  $pdf->Cell(40, 6, 'Qty.',  1, 0, 'C', 0);
  $pdf->Cell(40, 6, 'Rate',   1, 0, 'C', 0);
  $pdf->Cell(40, 6, 'Amount', 1, 0, 'C', 0);
}
?>